import JSEncrypt from 'jsencrypt';

// 后端提供的公钥（注意：公钥可以公开，私钥必须保密）
const PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmit6k0gyc
pQNVgmipcXDPZ+N7b0Q4m3GeOcS1rUSO2nprPUmWsTB9tvum8nPgW
jpR1XYo/nAgvwKOAdvkmG6O90ES4DkWM+uh8LbRsSSi05O91TgQUp
ybuNFFnG9O2ZAGKfJK/fOK7squ/2Q3GMAPmIpFDLYlPuE3BbjjP7j
o2Soan5br1xQvFtkCVwZNUq2buYoKokSDZM4X0SZAbMYoSgJS0EBL
kCYgOZXVdsFF7GeB1Azm582uNA3CBewLYKR+iFSdIrdt4vWzT9dxK
C97yCcEXe2S64HBhyTFhwvvj8vrFf3AwRE7HIej3eKfgR9nxvDLz8
AZz037xFEbuWryQIDAQAB
-----END PUBLIC KEY-----`;

// 加密函数：用公钥加密明文
export function encryptPassword(password) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(PUBLIC_KEY); // 设置公钥
  return encryptor.encrypt(password); // 加密密码
}